<template>
  <div>
    <!-- 添加或修改公告对话框 -->
    <el-dialog title="验收完成" :visible.sync="$parent.opendetailed" width="75%" append-to-body>
      <div class="center_dialog children">
        <el-divider>基本信息</el-divider>
        <el-descriptions direction="vertical" :column="4" border>
          <el-descriptions-item label="任务单编号">{{ form.upkeepTaskNum || '-' }}</el-descriptions-item>
          <el-descriptions-item label="申请单号">{{ form.ukPlanPartInfoVo && form.ukPlanPartInfoVo && form.ukPlanPartInfoVo
              &&
              form.ukPlanPartInfoVo.upkeepPlanNum || '-'
          }}</el-descriptions-item>
          <el-descriptions-item label="标题">{{ form.ukPlanPartInfoVo && form.ukPlanPartInfoVo.title || '-' }}
          </el-descriptions-item>
          <!-- <el-descriptions-item label="设备编号">{{ form.equipmentNum || '-' }}</el-descriptions-item>
          <el-descriptions-item label="设备名称">{{ form.equipmentName || '-' }}</el-descriptions-item>
          <el-descriptions-item label="供应商">{{ form.supplierName || '-' }}</el-descriptions-item> -->
          <el-descriptions-item label="负责人">
            <span v-for="(v, i) in form.upkeepPlanMaintainerList" :key="i">
              {{ v.maintainerName || '-' }}
              <template v-if="i !== form.upkeepPlanMaintainerList.length - 1">
                ,
              </template>
            </span>
            <!-- {{ form.ukPlanPartInfoVo && form.ukPlanPartInfoVo.headName || '-' }} -->
          </el-descriptions-item>
          <el-descriptions-item label="所属部门">{{ form.ukPlanPartInfoVo && form.ukPlanPartInfoVo.deptName || '-' }}
          </el-descriptions-item>
          <el-descriptions-item label="循环类型">{{ ['循环保养', '单次保养'][form.ukPlanPartInfoVo && form.ukPlanPartInfoVo &&
              form.ukPlanPartInfoVo && form.ukPlanPartInfoVo.generateTaskType] || '-'
          }}</el-descriptions-item>
          <el-descriptions-item label="生成任务">{{ ['提前一日', '提前二日', '提前三日',
              '提前四日', '提前五日'][form.ukPlanPartInfoVo && form.ukPlanPartInfoVo.generateTaskType]
              || '-'
          }}
          </el-descriptions-item>

          <el-descriptions-item label="验收人">{{ form.ukPlanPartInfoVo && form.ukPlanPartInfoVo.acceptorName || '-' }}
          </el-descriptions-item>
          <el-descriptions-item label="验收人部门">{{ form.ukPlanPartInfoVo && form.ukPlanPartInfoVo.acceptanceDeptName ||
              '-'
          }}</el-descriptions-item>
          <el-descriptions-item label="验收方式">{{ form.ukPlanPartInfoVo && form.ukPlanPartInfoVo.acceptanceModeName || '-'
          }}</el-descriptions-item>
          <el-descriptions-item label="备注">{{ form.ukPlanPartInfoVo && form.ukPlanPartInfoVo.remark || '-' }}
          </el-descriptions-item>
          <!-- <el-descriptions-item label="计划保养日期">{{ form.planUpkeepTime || '-' }}</el-descriptions-item>
          <el-descriptions-item label="生成日期">{{ form.generateTime || '-' }}</el-descriptions-item> -->
        </el-descriptions>
        <!-- <el-descriptions :column="1" border>
          <el-descriptions-item label-class-name="left_herder" label="保养状态">
            <span v-for="(value, index) in form.upkeepTaskStatuses" :key="index">
              <dict-tag :options="upkeepStatus" :value="value.upkeepStatus" />
              ({{ value.acceptanceTime || '-' }})
              <span :style="{ 'margin': '0 5px' }" v-if="index !== form.upkeepTaskStatuses.length - 1">/</span>
            </span>
          </el-descriptions-item>
          <el-descriptions-item label="验收状态">
            <span v-for="(value, index) in form.upkeepTaskStatuses" :key="index">
              <dict-tag :options="acceptanceStatus" :value="value.acceptanceStatus" />
              ({{ value.acceptanceTime || '-' }})
              <span :style="{ 'margin': '0 5px' }" v-if="index !== form.upkeepTaskStatuses.length - 1">/</span>
            </span>
          </el-descriptions-item>

          <el-descriptions-item label="验收说明">
            <span v-for="(value, index) in form.upkeepTaskStatuses" :key="index">
              {{ value.explanation }} <span :style="{ 'margin': '0 5px' }"
                v-if="index !== form.upkeepTaskStatuses.length - 1">/</span>
            </span>

          </el-descriptions-item>
        </el-descriptions> -->
        <el-divider>保养标准</el-divider>
        <div v-for="(item, index) in form.upkeepTaskStatuses" :key="index">
          <el-table :data="item.upkeepTaskGenerProVos">
            <el-table-column label="序号" align="center" prop="order" width="50">
              <template slot-scope="scope">
                {{ scope.$index + 1 }}
              </template>
            </el-table-column>
            <el-table-column label="编号" align="center" width="160">
              <template slot-scope="scope">
                {{ scope.row.upkeepType && scope.row.upkeepType.typeNum || '-' }}
              </template>
            </el-table-column>
            <el-table-column label="名称" align="center" min-width="120">
              <template slot-scope="scope">
                {{ scope.row.upkeepType.typeName || '-' }}
              </template>
            </el-table-column>
            <!-- <el-table-column label="周期" align="center" min-width="120">
              <template slot-scope="scope">
                {{ ['一日', '一周', '十五日', '一月', '三月', '六月', '十二月', '不定'][scope.row.upkeepType &&
                    scope.row.upkeepType.cycle] ||
                    '-'
                }}
              </template>
            </el-table-column>
            <el-table-column label="排序" align="center" min-width="120">
              <template slot-scope="scope">
                {{ scope.row.upkeepType && scope.row.upkeepType.sort || '-' }}
              </template>
            </el-table-column> -->
            <!-- <el-table-column label="状态" align="center" min-width="120">
                                <template slot-scope="scope">
                                  <dict-tag :options="statusFlag" :value="scope.row.status" />
                                </template>
                              </el-table-column> -->
            <el-table-column label="备注" align="center" min-width="180">
              <template slot-scope="scope">
                {{ scope.row.upkeepType && scope.row.upkeepType.remark || '-' }}
              </template>
            </el-table-column>
            <el-table-column label="保养状态" align="center" width="100">
              <template slot-scope="scope">
                <el-switch v-model="scope.row.status" @change="handleChange(index, scope.$index, scope.row.status)"
                  active-color="#13ce66" inactive-color="#909399" active-value="1" inactive-value="0" disabled>
                </el-switch>
              </template>
            </el-table-column>
            <el-table-column label="保养说明" align="center" min-width="380" show-overflow-tooltip>
              <template slot-scope="scope">
                <!-- <template v-if="scope.row.status === '1'">
                  <el-input v-model="scope.row.explanation"></el-input>
                </template> -->
                <!-- <template v-else> -->
                {{ scope.row.explanation || '-' }}
                <!-- </template> -->
              </template>
            </el-table-column>
          </el-table>
          <el-divider v-if="index !== form.upkeepTaskStatuses.length - 1">保养项目(重新保养)</el-divider>
        </div>
        <el-divider>配件更换</el-divider>
        <el-table v-if="form.ecrRemoveRecords.length !== 0" :data="form.ecrRemoveRecords" border>
          <el-table-column label="物料名称" prop="materialName">
          </el-table-column>
          <el-table-column label="数量" prop="amount">
          </el-table-column>
        </el-table>
        <el-empty v-else description="无配件更换" :image-size="35"></el-empty>
        <!-- <el-form ref="formData" style="width:100%" :model="formData" inline :rules="rules" label-width="80px">
          <el-form-item label="" prop="explanation" style="width:100%"> -->
        <el-input type="textarea" :rows="4" placeholder="请输入开机验收说明" v-model="formData.explanation">
        </el-input>
        <!-- </el-form-item>
        </el-form> -->
      </div>
      <div align="center" slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm('1')">通 过</el-button>
        <el-button type="danger" @click="submitForm('2')">不通过</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { getSelectChildrenupkeep, putAcceptanceCompleted } from "@/api/maintenance/insurance/insurance.js";
// import Upload from '@/components/upload/index.vue'
export default {
  props: ['rowObj'],
  components: {
    // Upload
  },
  data () {
    return {
      form: {

      },
      formData: {
        explanation: ''
      },
      replace: [],
      rules: {
        ecrRemoveRecords: { required: true, message: '必填', trigger: 'blur' },
      }
    }
  },
  created () {
    this.getlist()
  },
  methods: {
    handleChange (index, key, value) {
      if (value === '0') {
        this.form.upkeepTaskStatuses[index].upkeepTaskGenerProVos[key].explanation = ''
      }
    },
    async getlist () {
      let res = await getSelectChildrenupkeep(this.rowObj.upkeepTaskId, this.rowObj.equipmentAccountId);//保养任务ID/设备台账ID

      this.form = res.data
    },
    //提交
    submitForm (index) {
      if ((!this.formData.explanation) && index === '2') return this.$message.error('不通过时验收说明不可为空')
      // this.$refs['formData'].validate((valid) => {
      // if (!valid) return false
      let params = {
        upkeepTaskId: this.rowObj.upkeepTaskId,
        acceptanceStatus: index,
        explanation: this.formData.explanation
      }
      putAcceptanceCompleted(params).then(res => {
        if (res.code === 200) {
          this.$message.success(res.msg)
          this.$parent.opendetailed = false
          this.$parent.getList()//重新查询列表
        }
      })

      // });
    },
  }
}
</script>

<style lang="scss" scoped>
.center_dialog {
  // text-align: center;
  width: 90%;
  margin: 0px auto;
}
</style>
<style>
::v-deep .el-form-item__content {
  width: 100%;
}
</style>